<?php
/**
 * 企业任务框架验证
 * User: liuxibiao
 * Date: 20171011
 */
namespace App\Http\Validators;

use Illuminate\Http\Request;
use Validator;

class VersionsValidator
{
    /**
     * @param Request $request
     * @return array
     * @author Liying
     * @name 添加版本信息
     */
    public static function save(Request $request)
    {
        $only = [
            'version_id',//版本id
            'version_code',//版本号
            'is_force',//是否强制更新
            'apk_url',//apk最新地址
            'app_type',//app类型
            'point',//升级内容
            'created_at',//更新时间
        ];

        $rules = [
            'version_code' => 'required',
            'is_force' => 'integer',
            'app_type' => 'required',
            'point' => 'required',
        ];

        $messages = [
            'version_code.required' => '版本号不能为空',
            'is_force.integer' => '添加错误',
            'app_type.required' => 'app类型',
            'point.required' => '升级内容',
        ];

        $input = $request->only($only);

        $validator = Validator::make($input, $rules, $messages);
        if ($validator->fails())
            exit(json_encode(['info'=>$validator->errors()->first(),'code'=>'1002']));

        return $input;
    }

}